/**
	@file _myfile.cpp
    Copyright (C) 2011  AlexK. <alexander.kaspar@gmail.com>
**/

#include <QFileDialog>

#include "_myfile.h"

/**
 * @brief Constructor of _MyFile Class
 *
 **/
_MyFile::_MyFile()
{
}

/**
 * @brief Open Dialog to open File or Directory
 *
 * @param file_or_dir const QString: 'd' for directory, 'f' for file
 * @return QString
 **/
QString _MyFile::get_Handle_to_Infile(const QString& file_or_dir, QString loc) {
	if (file_or_dir == "d") {
        return QFileDialog::getExistingDirectory(
                   this,
                   trUtf8("Verzeichnis öffnen"),
                   loc );
	}
	else if (file_or_dir == "f") {
        return QFileDialog::getOpenFileName(
                   this,
                   trUtf8("Datei öffnen"),
                   loc,
                   QString::null);
	}
//TODO if cancelButton clicked ??
}


/**
 * @brief Path and Filename of infile
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ifxfullFileName(const QString &infile) {
    build_ofxFile(infile);
    return this->ifxfullFileName;
}

/**
 * @brief Filename w/o Path
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ifxFileName(const QString &infile) {
    build_ofxFile(infile);
    return this->ifxFileName;
}
/**
 * @brief Filename w/o Path and suffix
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ifxbaseName(const QString &infile) {
    build_ofxFile(infile);
    return this->ifxbaseName;
}

/**
 * @brief Path of infile w/o Filename
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ifxpath(const QString &infile) {
    build_ofxFile(infile);
    return this->ifxpath;
}

/**
 * @brief get suffix of infile
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ifxsuffix(const QString& infile)
{
	build_ofxFile(infile);
	return this->suf;
}

/**
 * @brief OFX Filename and Path
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ofxfullFileName(const QString &infile) {
    build_ofxFile(infile);
    return this->ofxfullFileName;
}

/**
 * @brief changes '.ifxxml' to '.ofx' on infile Name
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ofxName(const QString &infile) {
    build_ofxFile(infile);
    return this->ofxName;
}

/**
 * @brief add '/ofx' to ifxpath
 *
 * @param infile ...
 * @return QString
 **/
QString _MyFile::get_ofxpath(const QString &infile) {
    build_ofxFile(infile);
    return this->ofxpath;
}

bool _MyFile::is_dir(const QString &infile) {
    return _isdir;
}

bool _MyFile::exists(const QString& infile) {
    return _exists;
}

bool _MyFile::is_file(const QString& infile) {
    return _isfile;
}

/**
 * @brief fill variables of infile
 *
 * @param infile file to get information from
 * @return void
 **/
void _MyFile::build_ofxFile(const QString& infile) {
    QFileInfo fInfo(infile);

    this->ifxfullFileName = infile;
	this->ifxFileName = fInfo.fileName();
    this->ifxpath = fInfo.absolutePath();
    this->ifxbaseName = fInfo.baseName();
    this->suf = fInfo.suffix();

    this->ofxName = this->ifxbaseName + QString(".ofx");
    this->ofxpath = this->ifxpath + QString("/ofx/");
    this->ofxfullFileName = this->ofxpath + this->ofxName;

    _isdir = fInfo.isDir();
	_isfile = fInfo.isFile();
    _exists = fInfo.exists();
}






